<template>
  <div>
    <el-table
      :data="roleList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="角色编号"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="danger" v-if="scope.row.status==1"> 启用 </el-button>

            <el-button type="danger" v-else> 禁用 </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作"> 
        <template slot-scope="scope">
          <div>
            <el-button type="danger" @click="dit(scope.row.id)"> 编辑 </el-button>

            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {roleDelete} from '../../../requster/api'
import vDel from '../../../components/del.vue'
import {warningAlert,successAlert} from "../../../util/alter"
export default {
  props: ['obj'],
  components: {
    vDel,
  },
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      roleList: "role/list",
    }),
  },
  methods: {
    ...mapActions({
      reqroleList: "role/reqchangeList",
    }),
    // 删除功能
    del(id){
      roleDelete({id:id}).then(res=>{
        if(res.data.code==200){
         successAlert(res.data.msg)
         this.reqroleList()
        }else{
          warningAlert(res.data.msg)
        }
      })
    },
    // 编辑功能
    dit(id){
    this.$emit("dit",id)
    }
  },
  mounted() {
    this.reqroleList();
  },
};
</script>
<style scoped>
</style>